package com.app.repository.impl;

import com.app.model.main.User;
import com.app.repository.interfaces.UserMapper;
import com.app.support.dao.MybatisDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lichaojie on 2017/3/11. It's a beautiful day.
 */
@Repository
public class UserMapperImpl implements UserMapper {

    @Autowired
    private MybatisDao mybatisDao;

    @Override
    public int deleteByPrimaryKey(Long id){
        return mybatisDao.delete("com.app.dao.main.UserMapper",".deleteByPrimaryKey",id);
    }

    @Override
    public int insert(User record){
        return mybatisDao.insert("com.app.dao.main.UserMapper",".insert",record);
    }

    @Override
    public int insertSelective(User record){
        return mybatisDao.insert("com.app.dao.main.UserMapper",".insertSelective",record);
    }

    @Override
    public User selectByPrimaryKey(Long id){
        return mybatisDao.get("com.app.dao.main.UserMapper",".selectByPrimaryKey",id);
    }

    @Override
    public int updateByPrimaryKeySelective(User record){
        return mybatisDao.update("com.app.dao.main.UserMapper",".updateByPrimaryKeySelective",record);
    }

    @Override
    public int updateByPrimaryKey(User record){
        return mybatisDao.update("com.app.dao.main.UserMapper",".updateByPrimaryKey",record);
    }

    @Override
    public User selectByUserName(String userName, byte type){
        Map<String,Object> map = new HashMap<>();
        map.put("userName",userName);
        map.put("type",type);
        return mybatisDao.get("com.app.dao.main.UserMapper",".selectByUserName",map);
    }

    @Override
    public User selectByUID(String uid, byte type){
        Map<String,Object> map = new HashMap<>();
        map.put("uid",uid);
        map.put("type",type);
        return mybatisDao.get("com.app.dao.main.UserMapper",".selectByUID",map);
    }

    @Override
    public long getMaxId(){
        return mybatisDao.count("com.app.dao.main.UserMapper",".getMaxId",null);
    }

    @Override
    public List<User> getAllUser(){
        return mybatisDao.getList("com.app.dao.main.UserMapper",".getAllUser");
    }
    @Override
    public int updateUserCoin(long id, long coin) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("coin",coin);
        return mybatisDao.update("com.app.dao.main.UserInfoMapper",".updateUserCoin",map);
    }

    @Override
    public int getUserCoin(long id) {
        return mybatisDao.get("com.app.dao.main.UserInfoMapper",".getUserCoin",id);
    }

    @Override
    public int updateUserTitle(long id, int title) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        return mybatisDao.update("com.app.dao.main.UserInfoMapper",".updateUserTitle",map);
    }

    @Override
    public int getUserTitle(long id) {
        return mybatisDao.get("com.app.dao.main.UserInfoMapper",".getUserTitle",id);
    }
}
